package Gui;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import javax.swing.JPanel;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
public class GridMap extends JPanel { // classe que servira de terreno para o robot se movimentar

    int Xinicial, Xfinal;
    int Yinicial, Yfinal;
    Obstaculo obstaculo;
    ArrayList<Obstaculo> ArrayObstaculos;

    public GridMap() { // construtor
        super();
        ArrayObstaculos = new ArrayList<Obstaculo>();
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        desenhaGrade(g);
        g.setColor(Color.RED);
        g.fillRect(Xinicial, Yinicial, Math.abs(Xfinal - Xinicial),Math.abs(Yfinal - Yinicial));
        repaint();
    }

    public void desenhaGrade(Graphics g) // desenha o grid
    {
        g.setColor(Color.LIGHT_GRAY);

        for(int x = 0; x < this.getBounds().getMaxX(); x += 10){

            g.drawLine((int) this.getBounds().getMinX() + x,
                       (int) this.getBounds().getMinY(),
                       (int) this.getBounds().getMinX() + x,
                       (int) this.getBounds().getMaxY());
        }

        for(int y = 0; y < this.getBounds().getMaxY(); y += 10){

            g.drawLine((int) this.getBounds().getMinX(),
                       (int) this.getBounds().getMinY() + y,
                       (int) this.getBounds().getMaxX(),
                       (int) this.getBounds().getMinY() + y);
        }
    }

    public void desenhaObstaculo(int inicioX, int inicioY, int finalX, int finalY) //desenha os obstaculos
    {
        this.Xinicial = inicioX;
        this.Yinicial = inicioY;
        this.Xfinal = finalX;
        this.Yfinal = finalY;

        obstaculo = new Obstaculo();
        obstaculo.setXinicial(Xinicial);
        obstaculo.setYinicial(Yinicial);
        obstaculo.setXfinal(Xfinal);
        obstaculo.setYfinal(Yfinal);
        ArrayObstaculos.add(obstaculo);
        System.out.println("quantidade de obstaculos:"+" " + ArrayObstaculos.size());
    }
    public ArrayList<Obstaculo> getArrayObstaculos() {
        return ArrayObstaculos;
    }
}